// pages/plugins//task-person-list/index.js
import pinyin from "wl-pinyin";

const app = getApp();
const { AskPage } = app._require("common/index");
AskPage({

  /**
   * 页面的初始数据
   */
  data: {
    AlphabetList : ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"],
     person_items :["村","镇","第三方"]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let addressList =[
     { "title":"李敏"}, { "title":"王玉"}, { "title":"周恒记"}, { "title":"张贵明"}, { "title":"匿名"}, { "title":"韩欢"},
     { "title":"尤饶"}, { "title":"黄跟"}, { "title":"胡福"}, { "title":"何读"}, { "title":"周福"}, { "title":"徐骨干"},
     { "title":"张仍然"}, { "title":"阿迪力"}, { "title":"买买提"}, { "title":"秦山哥"}, { "title":"华读"}, { "title":"陈真"},
     
   ];

   let addressNameList = [];
   for (let k in addressList) {
       addressNameList.push(addressList[k].title)
   }


   // console.log(employeeNameList);
   let firstName = {};
   let new_alphabetList = [];
   this.data.AlphabetList.forEach((item) => {
     firstName[item] = [];
     addressNameList.forEach((el) => {
       /** 主要在这一句，el代表每个名字如 “安琪拉” ，
         pinyin.getFirstLetter(el) 取的是名字的首字母 “AQL” ，
         .substring(0, 1) 就是只取第一个字符 ‘A’ **/
       let first = pinyin.getFirstLetter(el).substring(0, 1);
       if (first == item) {
         firstName[item].push(el)
         console.log(item);
         // if(new_alphabetList )
         var index = new_alphabetList.indexOf(item)
         if (index <0){
           new_alphabetList.push(item);
         }
         // new_alphabetList.push(item);
       }
     })
   })
   console.log(new_alphabetList);

   this.setData({
     "addressNameList":firstName,
     "AlphabetList":new_alphabetList
   })


},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  choseAllAction(){
    console.log("全选");
  },
  choseNextAction(){
    console.log("下一步");
    wx.navigateTo({
      url: './fill-task/index',
    })
  }
})